import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:flutter_widgets_pc/resources/kq_theme_colors.dart';
import 'package:flutter_widgets_pc/widgets/formItem/entity/kq_form_entity.dart';
import 'package:flutter_widgets_pc/widgets/formItem/kq_header_item_view.dart';
import 'package:flutter_widgets_pc/widgets/sectionListView/kq_section_grid_view.dart';
import 'package:flutter_widgets_pc/widgets/titleBar/kq_title_bar.dart';

class SectionGridViewDemo extends StatefulWidget {
  const SectionGridViewDemo({super.key});

  @override
  State<SectionGridViewDemo> createState() => _SectionGridViewDemoState();
}

class _SectionGridViewDemoState extends State<SectionGridViewDemo> {
  List dataList = [
    ['1', '2', '3', '4', '5', '6'],
    ['1', '2', '3', '4', '5', '6'],
    ['1', '2', '3', '4', '5', '6'],
  ];

  Color getBackGroundColor(value) {
    Color color = KqThemeColors.bgF4;
    if (value == '1') {
      color = KqThemeColors.textGreen;
    } else if (value == '2') {
      color = KqThemeColors.textGreen;
    } else if (value == '3') {
      color = KqThemeColors.textBlue;
    } else if (value == '4') {
      color = KqThemeColors.textYellow;
    } else if (value == '5') {
      color = KqThemeColors.textRed;
    }
    return color;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: KqHeadBar(
        headTitle: '分区网格',
        back: () {
          Get.back();
        },
      ),
      body: KqSectionGridView(
        section: dataList.length,
        itemList: ((section) {
          return dataList[section];
        }),
        gridHeaderBuilder: () {
          return Container(
            height: 100,
            alignment: Alignment.center,
            color: KqThemeColors.bgWhite,
            child: Text(
              '列表头部',
              style: TextStyle(fontSize: 20),
            ),
          );
        },
        axisCount: ((section) {
          return SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: section + 3,
            crossAxisSpacing: 10.0 - section,
            mainAxisSpacing: 8,
          );
        }),
        sectionHeaderBuilder: (section) => KqHeaderItemView(
            entity: KqFormEntity(title: '分区头部${section.toString()}')),
        sectionFooterBuilder: (section) => KqHeaderItemView(
            entity: KqFormEntity(title: '分区尾部${section.toString()}')),
        itemBuilder: (section, row, object) {
          String number = object as String;
          return Container(
            alignment: Alignment.center,
            color: getBackGroundColor(number),
            child: Text(number),
          );
        },
      ),
    );
  }
}
